//
//  ZFBDetailNoteController.m
//  支付宝
//
//  Created by GD on 16/8/7.
//  Copyright © 2016年 HM. All rights reserved.
//

#import "ZFBDetailNoteController.h"

@interface ZFBDetailNoteController ()

@property (nonatomic,weak) UITextView *txtView;

@end

@implementation ZFBDetailNoteController

#pragma mark - event (selctor --btn,notification,itemBtn)
-(void)clickCancel
{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"reloadViewNotification" object:nil userInfo:nil];//为什么要发送通知?
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)clickSave
{
    //    NoteBL *bl = [[NoteBL alloc] init];
    //    Note *note = [[Note alloc] init];
    //    note.date = [Tool getLocalDateStr];
    //    note.content = self.txtView.text;
    //    NSMutableArray *reslist = [bl createNote:note];
    
    //    [[NSNotificationCenter defaultCenter] postNotificationName:@"reloadViewNotification" object:reslist userInfo:nil];
    //    [self.txtView resignFirstResponder];
    //    ZFBNoteModel *noteModel = [[ZFBNoteModel alloc] init];
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    //    //    dict[kZFBNoteDateKey = [NSDate date].description;
    //    //    noteModel.kZFBNoteContentKey = _txtView.text;
    [dict setValue:self.detailNoteDict[kZFBNoteDateKey] forKey:kZFBNoteDateKey];
    [dict setValue:_txtView.text forKey:kZFBNoteContentKey];//感觉setValue:forKey:是KVC的方法.
    [self.delegate detailNoteController:self didFinishEditNote:dict];
    
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setupUI];
    
    NSLog(@"%@",self.detailNoteDict);
    _txtView.text = self.detailNoteDict[kZFBNoteContentKey];
}


-(void)setupUI
{
    UITextView *txtView = [[UITextView alloc] initWithFrame:self.view.bounds];
    txtView.font = [UIFont systemFontOfSize:15];
    [self.view addSubview:txtView];
    self.txtView = txtView;
    
    //设置右上角按钮
    UIBarButtonItem *save = [[UIBarButtonItem alloc] initWithTitle:@"保存" style:UIBarButtonItemStylePlain target:self action:@selector(clickSave)];
    self.navigationItem.rightBarButtonItem = save;
    //设置左上角按钮
    UIBarButtonItem *cancel = [[UIBarButtonItem alloc] initWithTitle:@"取消" style:UIBarButtonItemStylePlain target:self action:@selector(clickCancel)];
    self.navigationItem.leftBarButtonItem = cancel;
    
    self.title = @"详情note";
    self.view.backgroundColor = [UIColor whiteColor];
}

@end
